package com.drophair.jspwork.Servlet;

import com.drophair.jspwork.bean.Sqlgoods;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Vector;

@WebServlet(name = "BuyGoodServlet", value = "/BuyGoodServlet")
public class BuyGoodServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");

        String goodid="",goodname="",goodprice="";
        goodid=request.getParameter("goodid");
        Sqlgoods sqlgoods=new Sqlgoods();
        try {
            Vector<String> vector=sqlgoods.getGoodInfo(goodid);
            goodid=vector.get(0);
            goodname=vector.get(1);
            goodprice=vector.get(2);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        request.setAttribute("goodid",goodid);
        request.setAttribute("goodname",goodname);
        request.setAttribute("goodprice",goodprice);
        request.getRequestDispatcher("/common/buy.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
